from ollama import chat

messages = [

]

while True:
    user_input = input('Chat with history: ')
    if user_input == 'q':
        break
    response = chat(
        'deepseek-r1:1.5b',
        messages=messages
                 + [
                     {'role': 'user', 'content': user_input},
                 ],
    )

    # Add the response to the messages to maintain the history
    messages += [
        {'role': 'user', 'content': user_input},
        {'role': 'assistant', 'content': response.message.content},
    ]
    print(messages)
    print(response.message.content + '\n')





# import requests
#
# messages = []
#
# while True:
#     question = input("question: ")
#     if question == "quit":
#         print("退出")
#         break
#     params = {
#         "model": "deepseek-r1:1.5b",
#         "messages": messages + [{"role": "user", "content": question}],
#         "stream": False
#     }
#     response = requests.post("http://localhost:11434/api/chat", json=params)
#     data = response.json()
#     messages += [
#         {"role": "user", "content": question},
#         data["message"]
#     ]
#     print(messages)
#     print("answer: ", data["message"]["content"])
